package rc.work.module.system.dal.mysql.dept;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import rc.work.framework.mybatis.core.mapper.BaseMapperX;
import rc.work.framework.mybatis.core.query.LambdaQueryWrapperX;
import rc.work.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import rc.work.module.system.dal.dataobject.dept.DeptDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface DeptMapper extends BaseMapperX<DeptDO> {

    default List<DeptDO> selectList(DeptListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeptDO>()
                .likeIfPresent(DeptDO::getName, reqVO.getName())
                .eqIfPresent(DeptDO::getStatus, reqVO.getStatus()));
//        LambdaQueryWrapper<DeptDO> wrapper = new LambdaQueryWrapper<DeptDO>()
//                .select(DeptDO::getId, DeptDO::getName, DeptDO::getStatus)
//                .like(reqVO.getName() != null, DeptDO::getName, reqVO.getName())
//                .eq(reqVO.getStatus() != null, DeptDO::getStatus, reqVO.getStatus());
//
//        return selectList(wrapper);
    }

    default DeptDO selectByParentIdAndName(String parentId, String name) {
        return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name);
    }

    default Long selectCountByParentId(String parentId) {
        return selectCount(DeptDO::getParentId, parentId);
    }

    default List<DeptDO> selectListByParentId(Collection<String> parentIds) {
        LambdaQueryWrapperX<DeptDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.in(DeptDO::getParentId, parentIds);
        queryWrapper.orderByAsc(DeptDO::getSort);
        return selectList(queryWrapper);
    }

    default List<DeptDO> selectListByLeaderUserId(Long id) {
        return selectList(DeptDO::getLeaderUserId, id);
    }


    IPage<DeptDO> selectDeptPage(Page<DeptDO> page, LambdaQueryWrapper<DeptDO> queryWrapper);
}
